#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from typing import Optional
from common.utils import LogUtil
from web_server.models.activities.scope_activity import ScopeActivity
from web_server.models.activities.drag_activity import DragActivity

logger = LogUtil.get_logger(__name__)

class ActivityFactory:
    """Activity工厂类，根据activity类型名创建activity实例"""
    _activity_classes = {
        "scope": ScopeActivity,
        "drag": DragActivity,
    }

    @classmethod
    def get_activity_types(cls):
        """获取所有activity类型"""
        return [activity_class.get_type_info() for activity_class in cls._activity_classes.values()]

    @classmethod
    def is_scoped(cls, typename: str) -> bool:
        """判断activity类型是否有作用域"""
        return cls._activity_classes.get(typename).is_scoped()

    @classmethod
    def create_activity(cls, typename: str, id: Optional[int] = None):
        """根据activity类型名创建activity实例"""
        activity_class = cls._activity_classes.get(typename)
        if id is None:
            return activity_class()
        else:
            return activity_class(id)